/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Cliente.View;

import Cliente.Controller.CadastroPresenter;
import Cliente.Controller.AlterarClientePresenter;
import Cliente.Controller.ConsultarClientePresenter;
import Cliente.Controller.GraficoPresenter;
import Cliente.Model.LogHtml;
import Cliente.Model.LogTxt;
import Cliente.util.ContarClientes;
import Cliente.util.DesktopPaneImagem;
import Cliente.util.Observer;
import Inteface.Log;
import javax.swing.JInternalFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;

/**
 *
 * @author Caio
 */
public class Clinica_Frame extends javax.swing.JFrame implements Observer {

    private DesktopPaneImagem desktopPane = new DesktopPaneImagem(".\\imagem\\pg2.jpg");
    private ContarClientes contacliente = new ContarClientes();
    CadastroPresenter cadastropresenter;
    /**
     * Creates new form Locadora_Frame
     */
    public Clinica_Frame() {
        initComponents();
        setSize(900, 700);
        setLocationRelativeTo(null);
        Jpanel.add(desktopPane, "card1");
        contacliente.contaClientes(lblContador);
       
    }

    public JMenuItem getMnuCadastroCliente() {
        return mnuCadastroCliente;
    }

    private void centralizaJanela(JInternalFrame internalFrame) {
        internalFrame.setLocation((this.getWidth() - internalFrame.getWidth()) / 2,
                (this.getHeight() - internalFrame.getHeight()) / 2);
    }

    @Override
    public void update(Integer i) {
      Integer a = Integer.parseInt(lblContador.getText());
      a=a+i;
      lblContador.setText(String.valueOf(a));
    }

    private Log decideLog(int a) {
        Log log = null;
        if (a == 0) {
            log = new LogHtml();
        } else if (a == 1) {
            log = new LogTxt();
        }
        return log;
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        lblContador = new javax.swing.JLabel();
        Jpanel = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        mnuCadastroCliente = new javax.swing.JMenuItem();
        mnuAlterar = new javax.swing.JMenuItem();
        mnuConsultar = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();

        jMenuItem3.setText("jMenuItem3");

        jMenuItem1.setText("jMenuItem1");

        jMenuItem2.setText("jMenuItem2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Clinica");
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jPanel1.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jLabel1.setText("Numero de Pacientes :");
        jPanel1.add(jLabel1);

        lblContador.setText("0");
        jPanel1.add(lblContador);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        getContentPane().add(jPanel1, gridBagConstraints);

        Jpanel.setLayout(new java.awt.CardLayout());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(Jpanel, gridBagConstraints);

        jMenuBar1.setBackground(new java.awt.Color(255, 0, 0));
        jMenuBar1.setForeground(new java.awt.Color(255, 0, 0));

        jMenu1.setText("Paciente");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        mnuCadastroCliente.setText("Cadastrar");
        mnuCadastroCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuCadastroClienteActionPerformed(evt);
            }
        });
        jMenu1.add(mnuCadastroCliente);

        mnuAlterar.setText("Alterar");
        mnuAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuAlterarActionPerformed(evt);
            }
        });
        jMenu1.add(mnuAlterar);

        mnuConsultar.setText("Consultar");
        mnuConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuConsultarActionPerformed(evt);
            }
        });
        jMenu1.add(mnuConsultar);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Gerar");
        jMenu2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu2ActionPerformed(evt);
            }
        });

        jMenuItem4.setText("Grafico");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem4);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnuAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuAlterarActionPerformed
        Object[] options = {"HTML", "TXT"};
        int resposta = JOptionPane.showOptionDialog(null, "Qual log deseja utilizar?", "Informação", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
        AlterarClientePresenter consultaClientePresenter = new AlterarClientePresenter(decideLog(resposta));
        desktopPane.add(consultaClientePresenter.view);
        centralizaJanela(consultaClientePresenter.view);
        consultaClientePresenter.registerObserver(this);
    }//GEN-LAST:event_mnuAlterarActionPerformed

    private void mnuCadastroClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuCadastroClienteActionPerformed
        Object[] options = {"HTML", "TXT"};
        int resposta = JOptionPane.showOptionDialog(null, "Qual log deseja utilizar?", "Informação", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
        cadastropresenter = CadastroPresenter.pegarInstancia(decideLog(resposta));
        desktopPane.add(cadastropresenter.getView());
        centralizaJanela(cadastropresenter.getView());
        cadastropresenter.registerObserver(this);
    }//GEN-LAST:event_mnuCadastroClienteActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed
    }//GEN-LAST:event_jMenu1ActionPerformed

    private void mnuConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuConsultarActionPerformed
        Object[] options = {"HTML", "TXT"};
        int resposta = JOptionPane.showOptionDialog(null, "Qual log deseja utilizar?", "Informação", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
        ConsultarClientePresenter cadastropresenter = new ConsultarClientePresenter(decideLog(resposta));
        desktopPane.add(cadastropresenter.view);
        centralizaJanela(cadastropresenter.view);
    }//GEN-LAST:event_mnuConsultarActionPerformed

    private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu2ActionPerformed
      
    }//GEN-LAST:event_jMenu2ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        GraficoPresenter graficoView = new GraficoPresenter();
        desktopPane.add(graficoView.view);  
        graficoView.view.setVisible(true);
        graficoView.gerarGraficoIMC();
        centralizaJanela(graficoView.view);
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Clinica_Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Clinica_Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Clinica_Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Clinica_Frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Clinica_Frame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel Jpanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lblContador;
    private javax.swing.JMenuItem mnuAlterar;
    private javax.swing.JMenuItem mnuCadastroCliente;
    private javax.swing.JMenuItem mnuConsultar;
    // End of variables declaration//GEN-END:variables
}
